<template>
  <div class="policy">
    <div class="policyTitle">
      <div class="policyTag" v-if="policy.typeName">{{ policy.typeName }}</div>
      <div class="policyPv">
      </div>
    </div>
    <div
      class="policyMsg"
      :style="!policy.typeName ? 'margin-top:0;':''"
      @click="$router.push({ path: 'policyDetail', query: { id: policy.id } })"
    >
      <div style="display: flex; justify-content: space-between; align-items: center">
        <div class="policyDate">{{ policy.no }}</div>
      </div>
      <div class="policyName">{{ policy.name }}</div>
    </div>
    <div class="policyFooter">
      <div class="policyUnit">
        <div>{{ '发文部门：' + policy.publishUnit }}</div>
        <div>{{ '申报日期：' + policy.beginDate + '至' + policy.closingDate }}</div>
      </div>
      <div class="policyUnit">
        <!-- <span>{{policy.createTime}}</span> -->
        <div v-if="policy.createTime">发文日期{{policy.createTime ?policy.createTime.replaceAll('-', '/').substr(0, 10):'' }}</div>
        <div v-else>&nbsp;</div>
        <div>{{ '阅读浏览：' + policy.pv + '次' }}</div>
      </div>
    </div>
    <div class="bot">
      <div class="bot-left"></div>
      <div class="bot-r">
        <div>
          <span
            style="margin-right:10px; color: #D00000; font-size: 15px; white-space: nowrap"
          >{{ policy.approachEnd == 1 ? '即将到期' : '' }}</span>
        </div>
        <div style="display: flex; align-items: center">
          <div
            class="policyApproachDay"
            v-if="policy.approachDay != null"
          >{{ '距开始还有' + policy.approachDay + '天' }}</div>
          <div
            class="policySendBtn"
            :style="'color :' + formatBtn(policy).color + '; background-color :' + formatBtn(policy).bgColor"
            v-if="policy.applyStatus != 2"
            @click="toPolicyDetail(policy)"
          >{{title?title:'立即申报'}}</div>
          <div
            class="policyCantSendBtn"
            :style="'color :' + formatBtn(policy).color + '; background-color :' + formatBtn(policy).bgColor"
            v-if="policy.applyStatus == 2"
          >已申报</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { formatLabel, formatSendBtn } from '@/utils/util.js'

export default {
  name: 'policyFrame',
  data() {
    return {}
  },
  props: {
    policy: {
      type: Object,
      default: {},
    },
    title:{
      type: String,
      default: "",
    }
  },
  methods: {
    /**
     * 跳转到政策详情页面
     */
    toPolicyDetail: function (policy) {
      let ns = this
      if (!formatSendBtn(policy).canIn) {
        return
      }
      ns.$router.push({
        path: 'policyDetail',
        query: { id: policy.id },
      })
    },
    /**
     * 格式化标签
     * @param label 标签名
     * @return {string|*} 标签名对象
     */
    formatLabel: function (label) {
      return formatLabel(label)
    },
    /**
     * 格式化显示按钮颜色
     */
    formatBtn: function (policy) {
      return formatSendBtn(policy)
    },
  },
}
</script>

<style scoped>
#policyList .policy {
  width: 586px;
  /* height: 216px; */
  border: 1px solid #e1e1e1;
  margin-bottom: 20px;
  position: relative;
  text-align: left;
}

#policyList .policy:hover {
  box-shadow: 0px 5px 5px #e1e1e1;
  transition: all 0.2s ease 0s;
}

#policyList .policy .policyTitle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
}

#policyList .policy .policyTitle .policyTag {
  padding: 8px 20px;
  /* background-color: #F7F1EB; */
  /* color: #f09450; */
  background: #f4fbff;
  color: #5f89e6;
  font-size: 15px;
}

#policyList .policy .policyTitle .policyPv {
  display: flex;
  align-items: center;
  margin-right: 20px;
  color: #999999;
}

#policyList .policy .policyMsg {
  margin: 20px 20px 0;
}

#policyList .policy .policyMsg:hover {
  cursor: pointer;
}

#policyList .policy .policyMsg .policyDescription {
  font-size: 12px;
  color: #999999;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  line-height: 20px;
}

#policyList .policy .policyMsg .policyDate {
  font-size: 12px;
  color: #999999;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#policyList .policy .policyMsg .policyName {
  font-size: 20px;
  font-weight: bold;
  margin: 5px 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
}

#policyList .policy .policyMsg:hover .policyName {
  color: #045db9;
}

#policyList .policy .policyFooter {
  /* position: absolute;
  bottom: 20px; */
  display: flex;
  /* justify-content: space-between; */
  align-items: center;
  width: 100%;
}

#policyList .policy .policyFooter .policyUnit {
  font-size: 12px;
  color: #999999;
  margin-left: 20px;
}
.policyUnit div:first-child {
  max-width: 240px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
/* #policyList .policy .policyFooter .policyApproachDay {
  font-size: 12px;
  color: #d00000;
  margin-right: 10px;
} */
.policyApproachDay {
  font-size: 12px;
  color: #d00000;
  margin-right: 10px;
}
/* #policyList .policy .policyFooter .policySendBtn {
  background-color: #045db9;
  color: #f1f2f4;
  padding: 10px 0px;
  width: 100px;
  font-size: 15px;
  margin-right: 20px;
  text-align: center;
  border-radius: 5px;
} */
.policySendBtn {
  background-color: #045db9;
  color: #f1f2f4;
  padding: 6px 0px;
  width: 100px;
  font-size: 15px;
  margin-right: 20px;
  text-align: center;
  border-radius: 5px;
}
/* #policyList .policy .policyFooter .policySendBtn:hover {
  cursor: pointer;
  background-color: #045db9;
  color: #f1f2f4;
  transition: all 0.2s ease 0s;
} */
.policySendBtn:hover {
  cursor: pointer;
  background-color: #045db9;
  color: #f1f2f4;
  transition: all 0.2s ease 0s;
}
/* #policyList .policy .policyFooter .policyCantSendBtn {
  background-color: #f1f2f4;
  color: #999999;
  padding: 10px 0px;
  width: 100px;
  font-size: 15px;
  margin-right: 20px;
  text-align: center;
  border-radius: 5px;
} */
.policyCantSendBtn {
  background-color: #f1f2f4;
  color: #999999;
  padding: 7px 0px;
  width: 100px;
  font-size: 15px;
  margin-right: 20px;
  text-align: center;
  border-radius: 5px;
}
/* #policyList .policy .policyFooter .policyCantSendBtn:hover {
  cursor: pointer;
} */
.policyCantSendBtn:hover {
  cursor: pointer;
}
.bot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  border-top: 1px solid #e1e1e1;
  padding: 4px 0;
}
.bot-r {
  display: flex;
  align-items: center;
}
</style>
